<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page import="com.wxtf.platform.plugins.user.*"%>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
	UserBean user = (UserBean)request.getSession().getAttribute("userBean");
	
	String _db = user.getDbType();

%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<base href="<%=basePath%>"/>
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta http-equiv="pragma" content="no-cache"/>
		<meta http-equiv="cache-control" content="no-cache"/>
		<meta http-equiv="expires" content="0"/>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<link type="text/css" rel="stylesheet" href="ligerUI/skins/Aqua/css/ligerui-all.css" />
		<link type="text/css" rel="stylesheet" href="ligerUI/skins/<%=user.getUserCss()%>/css/ligerui-all.css" />
		<link type="text/css" rel="stylesheet" href="ligerUI/skins/ligerui-icons.css" />
		<link type="text/css" rel="stylesheet" href="resource/css/style.css" />
		<script type="text/javascript" src="js/jquery/jquery-1.7.2.js"></script>
		<script type="text/javascript" src="ligerUI/js/core/base.js"></script>
		<script type="text/javascript" src="ligerUI/js/ligerui.min.js"></script>
		<script type="text/javascript" src="js/common.js"></script>
		<script type="text/javascript" src="js/validata.js"></script>
		<script type="text/javascript" src="ligerUI/js/plugins/ligerGrid.js"></script>
		<script type="text/javascript" src="ligerUI/js/plugins/ligerTree.js"></script>
		<script type="text/javascript" src="ligerUI/js/plugins/ligerForm.js"></script>
		<script type="text/javascript" src="ligerUI/js/plugins/ligerDateEditor.js"></script>
		
<script type="text/javascript">
var _db = '<%=_db%>';

_jsonObj.classname = "com.wxtf.platform.main.sygl.faa_birth_recordAction";
_jsonObj.methodname = "";
_jsonObj.logicdata = "[]";

var _jsonObje = {
	"classname":"com.wxtf.platform.main.sygl.faa_birth_recordAction",
	"methodname":"listAll",
	"logicdata":"[{\"fathername\":\"\",\"mothername\":\"\"}]"
};

var win;//人员新建/修改弹出框
var win2;//选人弹出框

var manager;//人员表格

$(function(){
	manager = $("#emp-grid").ligerGrid({
		url: _url, parms: _jsonObj,width: '100%', height: '100%',
		usePager: true, rownumbers: true, checkbox: true, alternatingRow: true,
		columns: [
			{ display: 'tbefbr_id', name: 'tbefbr_id', hide: true,width:1 },
			{ display: 'org_id', name: 'org_id', hide: true,width:1 },
            {
                 display: '类别', name: 'tbefbr_type',width: 100, isSort:false,
                 render: function (row)
                 {
                    var html = '';
                    if(row.tbefbr_type=='0'){
                    		html = '一胎生育证明';
                    }else if(row.tbefbr_type=='1'){
                    		html = '再生育证明';
                    }
                    else{ html = '未登记';}
                    return html;
                 }
            },
            { display: '机构名称', name: 'reserve1', width: 110, align: 'left'},
			{ display: '员工姓名', name: 'tbefbr_mname', width: 100, align: 'left',render: function(record, index, value, oth){
					return " <a href='javascript:addData(" + JSON.stringify(record) + ")'>"+value+"</a>";
				}
			},
			{ display: '父亲身份证号', name: 'tbefbr_midcard', width: 1, hide: true},
			{ display: '父亲工作单位', name: 'tbefbr_mdepartment', width: 1,hide: true},
			{ display: '配偶姓名', name: 'tbefbr_fname', width: 100, align: 'left' },
			{ display: '母亲身份证号', name: 'tbefbr_fidcard', width: 1, hide: true},
			{ display: '母亲工作单位', name: 'tbefbr_fdepartment', width: 1, hide: true},
			{ display: '结婚时间', name: 'tbefbr_married_time', width: 120, align: 'left' },
			{ display: '结婚证号', name: 'tbefbr_marriage_certificate',width:  1, hide:true},
			{ display: '办证时间', name: 'tbefbr_agree_birth_btime', width: 150, align: 'left' },
			{ display: '生育指标批准截止时间', name: 'tbefbr_agree_birth_etime',width:1,hide:true},
			{ display: '备注', name: 'tbefbr_memo', width:  1, hide:true },
			{ display: 'tbe_marital_status', name: 'tbe_marital_status', width:  1, hide:true },
			{ display: 'reserve2', name: 'reserve2', width:  1, hide:true },
			{ display: 'reserve3', name: 'reserve3', width:  1, hide:true },
			{ display: 'reserve4', name: 'reserve4', width:  1, hide:true },
			{ display: 'reserve5', name: 'reserve5', width:  1, hide:true },
			{ display: '录入人', name: 'create_by', width:  1, hide:true },
			{ display: '录入时间', name: 'create_time', width:  1, hide:true },
			{ display: '最后修改人', name: 'last_modify_by', width:  1, hide:true },
			{ display: '最后修改时间', name: 'last_modify_time', width: 1, hide:true },
			{ display: '编辑', name:'edit', isSort:false,width:60,render: function(record, index, value, oth){
					return "<img src='ligerUI/skins/icons/edit.gif' onclick='addData(" + JSON.stringify(record) + ")'></img>";
				}
			}
		],
		toolbar: {
			items: [
				{ text: '登记', click: function(){ addData(); }, icon: 'add' },
				{ line: true },
				{ text: '删除', click: function(){ delData(); },icon: 'delete'}
			]
		}
		
	});

	
	/*
	 * 日期框
	*/
	$("#tbefbr_married_time").ligerDateEditor({ format: "yyyy-MM-dd", width:182 });
	$("#tbefbr_agree_birth_btime").ligerDateEditor({ format: "yyyy-MM-dd", width:182});
	$("#tbefbr_agree_birth_etime").ligerDateEditor({ format: "yyyy-MM-dd", width:182}); 
	$("#ser4").ligerDateEditor({ format: "yyyy-MM-dd", width:164}); 
	$("#ser5").ligerDateEditor({ format: "yyyy-MM-dd", width:164}); 
});


/*
 * 表格刷新
 */
function reload(){
	_jsonObj.methodname = "queryPage";
	_jsonObj.logicdata = "[{\"types\":\"init\"}]";
	manager.loadData();
}

/*
 * ajax成功回调
 */
function ajaxCallbackSuccFunc(data, textStatus){
	serch1();
	if(data.result || data.result == 'true'){
		succMsgTip(data.resultrecord);
	}else{
		warningTip(data.resultrecord);
	}
	if(win && data.result){
		win.hide();
	}
}

/*
 * ajax失败回调
 */
function ajaxCallbackErrorFunc(data, textStatus){
	warningTip(data.resultrecord);
}

/*
 * 获取列表选中的人员ID
 */
function getUserIds(){
	var arrayUsers = manager.getSelecteds();
	if(arrayUsers.length == 0){
		return "";
	} else {
		var text = "";
		for(var i=0; i<arrayUsers.length; i++){
			text += arrayUsers[i].tbefbr_id + ",";
		}
		return text.substring(0, text.length - 1);
	}
}

/*
 * 新增/修改人员
 */
function addData(row){
	document.getElementById('emp-form').reset();
	document.getElementById("empBtn").disabled = false;//使可用
	$("#tbefbr_married_time").ligerGetDateEditorManager().setDisabled();//不可用
	if(row){
		loadForm("emp-form", row);
		
		document.getElementById("empBtn").disabled = true;//使不可用
	} else {
		$("#tbefbr_id").val('');
	}
	
	if(win == null){
		win = initWindowByDiv('empAdd-div', '编辑信息', 650, 400 ,save, closeWin);
	}else{
		win.show();
	}
}

/*
 * 新建/修改人员信息
 */
function save(){
	var time = $('#tbefbr_agree_birth_btime').val();
	var tbefbr_memo = $('#tbefbr_memo').val();
	if(time=='')
	{
		warningTip('请填写办证时间');
		return;
	}
	var tbfi_id = $('#tbfi_id').val();
	if(tbfi_id=='')
	{
		warningTip('请选择家庭人员信息');
		return;
	}
	if(!checkIsString(tbefbr_memo)){
		warningTip("备注：必须为字母、数字、下划线、中文组成");
		return;
	}
	if(fucCheckLength(tbefbr_memo) > 512){
		warningTip("备注：不能超过512字符");
		return;
	}
	var text = document.getElementById('org_id');
	text = text.options[text.selectedIndex].text.replaceAll('-','');
	$('#reserve1').val(text);
	_jsonObj.logicdata = getForm("emp-form");
	var tbefbr_id = $("#tbefbr_id").val();
	if(tbefbr_id == ''){
		_jsonObj.methodname = "save";
		callserver(_jsonObj, ajaxCallbackSuccFunc, ajaxCallbackErrorFunc);
	} else {
		_jsonObj.methodname = "update";
		callserver(_jsonObj, ajaxCallbackSuccFunc, ajaxCallbackErrorFunc);
	}
}

/*
 * 删除人员
 */
function delData(){
	var userIds = getUserIds();
	if(userIds == ""){
		warningTip('请至少选择一行数据进行操作');
		return;
	}
	$.ligerDialog.confirm('确定要删除选中的数据吗？（删除不可恢复）', function (opt) { 			
		if(opt){
			_jsonObj.methodname = "delete";
			_jsonObj.logicdata = "[{\"ids\":\"" + userIds + "\"}]";
			callserver(_jsonObj, ajaxCallbackSuccFunc, ajaxCallbackErrorFunc);
		}
	});
}


/*
 * 重置-条件查询
 */
function serReset(){

	$('#ser3').val('');
	$('#ser2').val('');
	$('#ser1').val('');
}

/*
 * 条件查询
 */
function serch1(){
	var orgIds = $('#org2').val();
	var mother = $('#ser3').val();
	var type = $('#ser1').val();
	var father = $('#ser2').val();
	var time1 = $('#ser4').val();
	var time2 = $('#ser5').val();	
	
	_jsonObj.methodname = "queryPage";
	_jsonObj.logicdata = '[{\"orgIds\":\"' + orgIds	+ '\",\"father\":\"' + father + '\",\"tbe_name\":\"' + type+ '\",\"time1\":\"' + time1
			 + '\",\"time2\":\"' + time2+ '\",\"mother\":\"' + mother + '\",\"types\":\"serch1\"}]';
	manager.loadData();
}

/*
 * 新建弹出框
 */
function openEmp(){
	_jsonObje.logicdata = '[{\"fathername\":\"\",\"mothername\":\"\"}]';
	
	if(win2==null){
		win2 = initWindowByDiv('grid0-win', '选择人员', 650, 360, function(item, dialog){
			var row = grid0.getSelecteds();
			if(row.length != 1){
				warningTip('请选择一个用户');
				return;
			}
			$('#org_id').val(row[0].org_id);
			$('#tbfi_id').val(row[0].tbfi_id);
			$('#tbefbr_mname').val(row[0].tbefbr_mname);
			$('#tbefbr_midcard').val(row[0].tbefbr_midcard);
			$('#tbefbr_mdepartment').val(row[0].tbefbr_mdepartment);
			$('#tbefbr_fname').val(row[0].tbefbr_fname);
			$('#tbefbr_fidcard').val(row[0].tbefbr_fidcard);
			$('#tbefbr_fdepartment').val(row[0].tbefbr_fdepartment);
			$('#tbefbr_married_time').val(row[0].tbefbr_married_time);
			$('#tbefbr_marriage_certificate').val(row[0].tbefbr_marriage_certificate);
			win2.hide();
		}, closeWin);
		grid0 = $("#grid0-div").ligerGrid({
			url:_url, parms:_jsonObje, width: 620, height: 250,
			usePager: true, rownumbers: true, checkbox: true, alternatingRow: true,
			columns: [
				{ display: 'tbfi_id', name: 'tbfi_id', hide: true,width:1 },
				{ display: 'org_id', name: 'org_id', hide: true,width:1 },
				{ display: '机构名称', name: 'reserve1',align: 'left',width:150},
				{ display: '员工姓名', name: 'tbefbr_mname', width: 100, align: 'left' },
				{ display: '员工身份证号', name: 'tbefbr_midcard', width: 100, align: 'left'},
				{ display: '员工工作单位', name: 'tbefbr_mdepartment', width: 100, align: 'left'},
				{ display: '配偶姓名', name: 'tbefbr_fname', width: 100, align: 'left' },
				{ display: '配偶身份证号', name: 'tbefbr_fidcard',width: 100, align: 'left'},
				{ display: '配偶工作单位', name: 'tbefbr_fdepartment', width: 100, align: 'left'},
				{ display: '结婚时间', name: 'tbefbr_married_time', width: 120, align: 'left' },
				{ display: '结婚证号', name: 'tbefbr_marriage_certificate',width: 100, align: 'left'}
			],
			onCheckRow: function(checked, rowdata, rowindex) {
			    for (var rowid in this.records)
			        this.unselect(rowid); 
			    this.select(rowindex);
			}
		});
	} else {
		win2.show();
		grid0.loadData();
	}
	serempReset();
}
function serempReset()
{
	$('#fathername').val('');
	$('#mothername').val('');
}
/*
 * 选人弹出框-条件查询
 */
function serch2(){
	var fathername = $('#fathername').val().trim();
	var mothername = $('#mothername').val().trim();
	
	_jsonObje.logicdata = '[{\"fathername\":\"' + fathername + '\",\"mothername\":\"' + mothername + '\"}]'
	grid0.loadData();
}

/*
 * 条件导出查询
 */
function expDatas(){
	var orgIds = $('#org2').val();
	var mother = $('#ser3').val();
	var type = $('#ser1').val();
	var father = $('#ser2').val();
	var time1 = $('#ser4').val();
	var time2 = $('#ser5').val();
	
	_jsonObj.methodname = "expData";
	_jsonObj.logicdata = '[{\"orgIds\":\"' + orgIds	+ '\",\"father\":\"' + father + '\",\"tbe_name\":\"' + type+ '\",\"time1\":\"' + time1
			 + '\",\"time2\":\"' + time2+ '\",\"mother\":\"' + mother + '\",\"types\":\"serch1\"}]';
			
	callserver(_jsonObj, function(data, textStatus){
		if(data.result){
			parent.downloadFile(data.resultrecord);
		} else {
			warningTip(data.resultrecord);
		}
	}, function(data, textStatus){
	});
}

/*
 * 入厂时间验证
 */
function joinTime(ele){
	var tbe_work_area = $('#tbefbr_agree_birth_btime').val();
	var tbe_join_time = $('#tbefbr_agree_birth_etime').val();
	if('' != tbe_work_area && '' != tbe_join_time){
		var res = compareDate(tbe_work_area, tbe_join_time);
		if(null == res || res > 0){
			ele.value = '';
			warningTip('起始时间应早于或等于截止时间');
			return;
		}
	}
}

</script>
</head>
<body onload="window.status='完毕';">
	  <table id="aaa" class="serTable">
			<tr>
				<td>
					机构：<select id="org2" style=" width: 164px;">
						<%=user.getCurSubOrgOptions()%>
					</select>
				</td>
				<td>员工姓名：</td><td><input id="ser2" style="width: 160px;"/></td>
				<td>配偶姓名：</td><td><input id="ser3" style="width: 160px;"/></td>
				<td><input class="btn2" value="搜索" type="button" onclick="serch1();" /></td>
			</tr>
			<tr>
				<td>登记类别：
				<select id="ser1" style="width:164px;">
					<option value="2">全部</option>
					<option value="0">一胎生育证明</option>
					<option value="1">再生育证明</option>
					</select>
				</td>

				<td>起始时间：</td>
				<td><input id="ser4" onkeyup="this.value=formatdata(this.value);"/></td>
				<td>截止时间：</td>
				<td><input id="ser5" onkeyup="this.value=formatdata(this.value);"/></td>
				<td><input class="btn2" value="导出" type="button" onclick="expDatas();" /></td>
			</tr>
		</table>
		
		<div id="emp-grid"></div>
		
		<div id="empAdd-div" style="display: none;">
			<form id="emp-form" name="emp-form">
				<input type="hidden" id="tbefbr_id" name="tbefbr_id" value="" />
				<input type="hidden" id="tbfi_id" name="tbfi_id" value="" />
				<input type="hidden" id="tbefbr_agree_birth_etime" name="tbefbr_agree_birth_etime" value="" />
				<input type="hidden" id="reserve1" name="reserve1" value="" />
				<input type="hidden" id="reserve2" name="reserve2" value="" />
				<input type="hidden" id="reserve3" name="reserve3" value="" />
				<input type="hidden" id="reserve4" name="reserve4" value="" />
				<input type="hidden" id="reserve5" name="reserve5" value="" />
				<input type="hidden" id="create_by" name="create_by" value="" />
				<input type="hidden" id="create_time" name="create_time" value="" />
				<input type="hidden" id="last_modify_by" name="last_modify_by" value="" />
				<input type="hidden" id="last_modify_time" name="last_modify_time" value="" />
				
				<table class="form_table">
					<tr>
						<td colspan="9" align="left">
							<div style="border-bottom: 1px solid #EBEBEB; font-weight:bold;height: 28px; line-height: 28px;margin: 0 0 5px;" >
								<img src="ligerUI/skins/icons/communication.gif"/>
								<span>基础信息</span>
							</div>
						</td>
					</tr>
					<tr>
						<td class="form_label">机构：</td>
						<td>
							<select id="org_id" name="org_id" style=" width: 182px;">
								<%=user.getCurSubOrgOptions()%>
							</select>
						</td>
						<td><font color="red">*</font></td>
						<td class="form_label">员工姓名：</td>
						<td><input class="textbg1" id="tbefbr_mname" name="tbefbr_mname" readonly="readonly" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'"/></td>
						<td><input id="empBtn" name="empBtn" type="button" class="btn1" value="选人" onclick="openEmp();"/></td>
					</tr>
					<tr>
						<td class="form_label">员工身份证：</td>
						<td><input class="textbg1" id="tbefbr_midcard" name="tbefbr_midcard" readonly="readonly" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'"/></td>
						<td></td>
						<td class="form_label">工作单位：</td>
						<td><input class="textbg1" id="tbefbr_mdepartment" name="tbefbr_mdepartment" readonly="readonly" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'"/></td>
						<td></td>
					</tr>
					<tr>
						<td class="form_label">配偶姓名：</td>
						<td><input class="textbg1" id="tbefbr_fname" name="tbefbr_fname" readonly="readonly" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'"/></td>
						<td></td>
						<td class="form_label">配偶身份证：</td>
						<td><input class="textbg1" id="tbefbr_fidcard" name="tbefbr_fidcard" readonly="readonly" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'"/></td>
						<td></td>
					</tr>
					<tr>
						<td class="form_label">工作单位：</td>
						<td><input class="textbg1" id="tbefbr_fdepartment" name="tbefbr_fdepartment" readonly="readonly" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'"/></td>
						<td></td>
						<td class="form_label">结婚时间：</td>
						<td><input id="tbefbr_married_time" name="tbefbr_married_time" onkeyup="this.value=formatdata(this.value);"/></td>
						<td></td>
					</tr>
					<tr>
						<td class="form_label">结婚证号：</td>
						<td><input class="textbg1" id="tbefbr_marriage_certificate" readonly="readonly" name="tbefbr_marriage_certificate" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'"/></td>
						<td></td>
					</tr>
					<tr>
						<td colspan="9" align="left">
							<div style="border-bottom: 1px solid #EBEBEB; font-weight:bold;height: 28px; line-height: 28px;margin: 0 0 5px;" >
								<img src="ligerUI/skins/icons/communication.gif" />
								<span>生育证明信息</span>
							</div>
						</td>
					</tr>
					<tr>
						<td class="form_label">登记类别：</td>
						<td>
						<select id="tbefbr_type" name="tbefbr_type" style="width: 182px;">
							<option value="0">一胎生育证明</option>
							<option value="1">再生育证明</option>
						</select>	
						</td>	
						<td><font color="red">*</font></td>
						<td class="form_label">办证时间：</td>
						<td><input id="tbefbr_agree_birth_btime" name="tbefbr_agree_birth_btime" onkeyup="this.value=formatdata(this.value);"/></td>
						<td><font color="red">*</font></td>
					</tr>
					<tr>
						<td class="form_label">备注：</td>
						<td><input class="textbg1" id="tbefbr_memo" name="tbefbr_memo" onMouseOver="this.style.borderColor='#4fa8e6'" onMouseOut="this.style.borderColor='#A1A3A1'"/></td>
						<td></td>
					</tr>				
					<tr><td><br /></td></tr>
				</table>
			</form>
		</div>
		<div id="grid0-win" style="display: none;">
			<table class="serTable">
				<tr>
					<td>员工姓名：</td><td><input id="fathername" style=" width: 100px;"/></td>
					<td>配偶姓名：</td><td><input id="mothername" style=" width: 100px;"/></td>
					<td><input class="btn2" value="搜索" type="button" onclick="serch2();" /></td>
					<td><input class="btn2" value="重置" type="button" onclick="serempReset();" /></td>
				</tr>
			</table>
			<div id="grid0-div"></div>
		</div>
	</body>
</html>